﻿#region Using Directives

using System;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Utils;
using QuickDev.Common.Serialization;

using QuickDev.Model;
using QuickDev.SQLServerDAL;
using QuickDev.Caching;

#endregion

namespace QuickDev.BLL
{
    /// <summary>
    /// BLL Layer For dbo.OPM_ReturnOrderDetail.
    /// </summary>
    public class ReturnOrderDetailBLL
    {
        #region ReturnOrderDetailBLL.IsExist( int returnOrderId , string productNumber )
        /// <summary>
        /// public static bool IsExist( int returnOrderId , string productNumber )
        /// </summary>
        /// <param name="returnOrderId">returnOrderId</param>
        /// <param name="productNumber">productNumber</param>
        /// <returns>bool Existed</returns>
        public static bool IsExist( int returnOrderId , string productNumber )
        {
            Validation.ValidateIntegerIsGreaterThanZero( returnOrderId , "QuickDev.BLL.ReturnOrderDetailBLL.IsExist() Method -- returnOrderId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( productNumber , "QuickDev.BLL.ReturnOrderDetailBLL.IsExist() Method -- productNumber" );

            return ReturnOrderDetailDAL.IsExist( returnOrderId , productNumber );
        }

        #endregion

        #region ReturnOrderDetailBLL.Insert( int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int createdBy ) Method

        /// <summary>
        /// public static int Insert( int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int createdBy )
        /// </summary>
        /// <param name="returnOrderId">returnOrderId</param>
        /// <param name="productNumber">productNumber</param>
        /// <param name="productQty">productQty</param>
        /// <param name="returnTypeId">returnTypeId</param>
        /// <param name="returnReasonXML">returnReasonXML</param>
        /// <param name="otherReasonChecked">otherReasonChecked</param>
        /// <param name="otherReasonContent">otherReasonContent</param>
        /// <param name="createdBy">createdBy</param>
        /// <returns>ReturnOrderDetail model</returns>
        public static ReturnOrderDetail Insert( int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int createdBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( returnOrderId , "QuickDev.BLL.ReturnOrderDetailBLL.Insert() Method -- returnOrderId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( productNumber , "QuickDev.BLL.ReturnOrderDetailBLL.Insert() Method -- productNumber" );
            Validation.ValidateIntegerIsGreaterThanZero( productQty , "QuickDev.BLL.ReturnOrderDetailBLL.Insert() Method -- productQty" );
            Validation.ValidateIntegerIsGreaterThanZero( returnTypeId , "QuickDev.BLL.ReturnOrderDetailBLL.Insert() Method -- returnTypeId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( returnReasonXML , "QuickDev.BLL.ReturnOrderDetailBLL.Insert() Method -- returnReasonXML" );

            int newId = ReturnOrderDetailDAL.Insert( returnOrderId , productNumber , productQty , returnTypeId , returnReasonXML , otherReasonChecked , otherReasonContent , createdBy );

            if ( newId > 0 )
            {
                ReturnOrderDetailCache.RemoveAllCollectionFromCache();

                return ReturnOrderDetailCache.GetModel( newId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderDetailBLL.Update( int id , int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int updatedBy ) Method

        /// <summary>
        /// public static bool Update( int id , int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int updatedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="returnOrderId">returnOrderId</param>
        /// <param name="productNumber">productNumber</param>
        /// <param name="productQty">productQty</param>
        /// <param name="returnTypeId">returnTypeId</param>
        /// <param name="returnReasonXML">returnReasonXML</param>
        /// <param name="otherReasonChecked">otherReasonChecked</param>
        /// <param name="otherReasonContent">otherReasonContent</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>ReturnOrderDetail model</returns>
        public static ReturnOrderDetail Update( int id , int returnOrderId , string productNumber , int productQty , int returnTypeId , string returnReasonXML , bool otherReasonChecked , string otherReasonContent , int updatedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- id" );
            Validation.ValidateIntegerIsGreaterThanZero( returnOrderId , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- returnOrderId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( productNumber , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- productNumber" );
            Validation.ValidateIntegerIsGreaterThanZero( productQty , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- productQty" );
            Validation.ValidateIntegerIsGreaterThanZero( returnTypeId , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- returnTypeId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( returnReasonXML , "QuickDev.BLL.ReturnOrderDetailBLL.Update() Method -- returnReasonXML" );

            if ( ReturnOrderDetailDAL.Update( id , returnOrderId , productNumber , productQty , returnTypeId , returnReasonXML , otherReasonChecked , otherReasonContent , updatedBy ) )
            {
                ReturnOrderDetailCache.RemoveAllCollectionFromCache();
                ReturnOrderDetailCache.RemoveModelFromCache( id );

                return ReturnOrderDetailCache.GetModel( id );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderDetailBLL.Delete( int id , int deletedBy ) Method

        /// <summary>
        /// public bool Delete( int id , int deletedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>bool successful</returns>
        public static bool Delete( int id , int deletedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderDetailBLL.Delete -- id" );

            if ( ReturnOrderDetailDAL.Delete( id , deletedBy ) )
            {
                ReturnOrderDetailCache.RemoveAllCollectionFromCache();

                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}

